package f.f0.g;

import f.a0;
import f.d;
import f.f0.f.c;
import f.f0.f.g;
import f.m;
import f.s;
import f.s.a;
import f.y;
import java.io.IOException;
import java.util.List;

/* compiled from: RealInterceptorChain */
public final class f implements a {
    public final List<s> a;
    public final g b;
    public final c c;
    public final c d;
    public final int e;
    public final y f;
    public final d g;
    public final m h;
    public final int i;
    public final int j;
    public final int k;
    public int l;

    public f(List<s> list, g gVar, c cVar, c cVar2, int i, y yVar, d dVar, m mVar, int i2, int i3, int i4) {
        this.a = list;
        this.d = cVar2;
        this.b = gVar;
        this.c = cVar;
        this.e = i;
        this.f = yVar;
        this.g = dVar;
        this.h = mVar;
        this.i = i2;
        this.j = i3;
        this.k = i4;
    }

    public a0 a(y yVar) throws IOException {
        return b(yVar, this.b, this.c, this.d);
    }

    public a0 b(y yVar, g gVar, c cVar, c cVar2) throws IOException {
        if (this.e < this.a.size()) {
            StringBuilder g;
            this.l++;
            String str = "network interceptor ";
            if (this.c == null) {
                y yVar2 = yVar;
            } else if (!this.d.k(yVar.a)) {
                g = c.b.a.a.a.g(str);
                g.append(this.a.get(this.e - 1));
                g.append(" must retain the same host and port");
                throw new IllegalStateException(g.toString());
            }
            String str2 = " must call proceed() exactly once";
            if (this.c == null || this.l <= 1) {
                List list = this.a;
                int i = this.e;
                int i2 = i + 1;
                d dVar = this.g;
                m mVar = this.h;
                int i3 = this.i;
                int i4 = this.j;
                int i5 = i4;
                String str3 = str;
                int i6 = i;
                String str4 = str2;
                f fVar = new f(list, gVar, cVar, cVar2, i2, yVar, dVar, mVar, i3, i5, this.k);
                s sVar = (s) list.get(i6);
                a0 intercept = sVar.intercept(fVar);
                if (cVar == null || this.e + 1 >= this.a.size() || fVar.l == 1) {
                    String str5 = "interceptor ";
                    StringBuilder stringBuilder;
                    if (intercept == null) {
                        stringBuilder = new StringBuilder();
                        stringBuilder.append(str5);
                        stringBuilder.append(sVar);
                        stringBuilder.append(" returned null");
                        throw new NullPointerException(stringBuilder.toString());
                    } else if (intercept.g != null) {
                        return intercept;
                    } else {
                        stringBuilder = new StringBuilder();
                        stringBuilder.append(str5);
                        stringBuilder.append(sVar);
                        stringBuilder.append(" returned a response with no body");
                        throw new IllegalStateException(stringBuilder.toString());
                    }
                }
                g = new StringBuilder();
                g.append(str3);
                g.append(sVar);
                g.append(str4);
                throw new IllegalStateException(g.toString());
            }
            g = c.b.a.a.a.g(str);
            g.append(this.a.get(this.e - 1));
            g.append(str2);
            throw new IllegalStateException(g.toString());
        }
        throw new AssertionError();
    }
}
